﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Axis.Dao.Research;
using Axis.Web.Administrator.Global;
namespace Axis.Web.Administrator.Views.Project
{
    
    public class CResponseUI
    {
        public IList<CResponseOption> GetResponseList(string InputText)
        {

            JObject googleSearch = JObject.Parse(InputText);
            // get JSON result objects into a list
            IList<JToken> results = googleSearch["ResponseOption"].Children().ToList();
            // serialize JSON results into .NET objects
            IList<CResponseOption> searchResults = new List<CResponseOption>();
            foreach (JToken result in results)
            {
                CResponseOption searchResult = JsonConvert.DeserializeObject<CResponseOption>(result.ToString());
                searchResults.Add(searchResult);
            }
            return searchResults;
        }

        public IList<CResponseOption> GetResponseListCol(string InputText)
        {

            JObject googleSearch = JObject.Parse(InputText);
            // get JSON result objects into a list
            IList<JToken> results = googleSearch["ColOption"].Children().ToList();
            // serialize JSON results into .NET objects
            IList<CResponseOption> searchResults = new List<CResponseOption>();
            foreach (JToken result in results)
            {
                CResponseOption searchResult = JsonConvert.DeserializeObject<CResponseOption>(result.ToString());
                searchResults.Add(searchResult);
            }
            return searchResults;
        }

        public IList<CResponseOption> GetResponseListByQuestionnaire(int QuestionnaireID)
        {
            CResearchDao core = new CResearchDao();
            return core.GetResponseOption(string.Format("<InputValue UserID=\"{0}\" QuestionnaireID=\"{1}\" />", CSecurity.USER_ID.ToString(), QuestionnaireID));
        }
        public IList<CResponseOption> GetResponseListByQuestionnaire(int QuestionnaireID, string Context)
        {
            CResearchDao core = new CResearchDao();
            return core.GetResponseOption(string.Format("<InputValue UserID=\"{0}\" QuestionnaireID=\"{1}\" Context='{2}'/>", CSecurity.USER_ID.ToString(), QuestionnaireID, Context));
        }
        public IList<CResponseOption> GetResponseListByQuestionnaire2(string input)
        {
            CResearchDao core = new CResearchDao();
            return core.GetResponseOption(input);
        }
    }

}